import request from './request'

// 获取论坛统计数据
export function getForumStats() {
  return request({
    url: '/forum/stats',
    method: 'get'
  })
}

// 获取所有板块列表
export function getForumBoards() {
  return request({
    url: '/forum/boards',
    method: 'get'
  })
}

// 获取热门话题
export function getHotTopics(limit) {
  return request({
    url: '/forum/topics/hot',
    method: 'get',
    params: { limit }
  })
}

// 获取最新话题列表
export function getLatestTopics(page, size) {
  return request({
    url: '/forum/topics/latest',
    method: 'get',
    params: { page, size }
  })
}

// 获取求职指南列表（职业指导类型的话题）
export function getCareerGuides(params) {
  return request({
    url: '/forum/search',
    method: 'get',
    params: {
      ...params,
      category: '职业指导',
      boardId: 1  // 假设ID为1的板块是职业指导板块，也可以通过后端搜索关键词
    }
  })
}

// 获取板块详情和话题列表
export function getBoardDetail(boardId, params) {
  return request({
    url: `/forum/boards/${boardId}`,
    method: 'get',
    params
  })
}

// 获取话题详情
export function getTopicDetail(topicId) {
  return request({
    url: `/forum/topics/${topicId}`,
    method: 'get'
  })
}

// 获取话题回复列表
export function getTopicReplies(topicId, params) {
  return request({
    url: `/forum/topics/${topicId}/replies`,
    method: 'get',
    params
  })
}

// 创建新话题或更新话题
export function createTopic(data) {
  return request({
    url: '/forum/topics',
    method: 'post',
    data
  })
}

// 更新话题
export function updateTopic(topicId, data) {
  return request({
    url: `/forum/topics/${topicId}`,
    method: 'put',
    data
  })
}

// 删除话题
export function deleteTopic(topicId) {
  console.log(`[DEBUG] 调用删除话题API，话题ID: ${topicId}`)
  return request({
    url: `/forum/topics/${topicId}`,
    method: 'delete'
  })
}

// 发表回复
export function createReply(data) {
  return request({
    url: '/forum/replies',
    method: 'post',
    data
  })
}

// 删除回复
export function deleteReply(replyId) {
  return request({
    url: `/forum/replies/${replyId}`,
    method: 'delete'
  })
}

// 点赞话题
export function likeTopic(topicId) {
  return request({
    url: `/forum/topics/${topicId}/like`,
    method: 'post'
  })
}

// 取消点赞话题
export function unlikeTopic(topicId) {
  return request({
    url: `/forum/topics/${topicId}/unlike`,
    method: 'post'
  })
}

// 点赞回复
export function likeReply(replyId) {
  return request({
    url: `/forum/replies/${replyId}/like`,
    method: 'post'
  })
}

// 取消点赞回复
export function unlikeReply(replyId) {
  return request({
    url: `/forum/replies/${replyId}/unlike`,
    method: 'post'
  })
}

// 搜索话题
export function searchTopics(params) {
  return request({
    url: '/forum/search',
    method: 'get',
    params
  })
}

// 获取用户的话题列表
export function getUserTopics(userId, params) {
  return request({
    url: `/forum/users/${userId}/topics`,
    method: 'get',
    params
  })
}

// 获取用户的回复列表
export function getUserReplies(userId, params) {
  return request({
    url: `/forum/users/${userId}/replies`,
    method: 'get',
    params
  })
}

// 设置话题为精华
export function setTopicEssence(topicId, isEssence) {
  return request({
    url: `/forum/topics/${topicId}/essence`,
    method: 'post',
    data: { isEssence }
  })
}

// 设置话题置顶
export function setTopicTop(topicId, isTop) {
  return request({
    url: `/forum/topics/${topicId}/top`,
    method: 'post',
    data: { isTop }
  })
} 